<template>
  <div>
    <div v-show="changeShow" style="margin:20px;">
      <el-button
        size="medium"
        align="center"
        type="primary"
        @click="goBack"
        >
        返回
      </el-button>
      <eChild :proId='proId' @func='getStatus' :changeShow='changeShow' ref="mychild"/>
    </div>
  <div class="app-container" v-show="!changeShow">
    <div class="filter-container">
      <span style="margin-left:3%">商品类型:</span>
      <el-cascader :options="areaData" clearable size="small" ref="area" :props="{value: 'catId', label: 'name',children:'proCatInfo'}" @change="areaChange" style="width:300px"></el-cascader>
      <span style="margin-left:3%">提交时间:</span>
      <el-date-picker
        v-model="value1"
        type="datetimerange"
        range-separator="——"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        size="small"
        value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
      <el-button
        size="small"
        class="filter-item"
        type="success"
        icon="el-icon-search"
        style="margin-left:3%"
        @click="handleFilter"
        >
        搜索
      </el-button>
    </div>

    <el-table
      :key="tableKey"
      :data="list"
      size="small"
      border
      fit
      highlight-current-row
      style="width: 100%;margin-top:1%"
    >
    <el-table-column type="index" label="序号">
    </el-table-column>
    <el-table-column label="商品类型" width="300px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.catName }}</span>
          <!-- <img :src="scope.row.imgUri" style="width:300px;height:200px" alt=""> -->
        </template>
      </el-table-column>
      <el-table-column label="商品名称" min-width="250px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.infoName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提交时间" width="200px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发布所属区/县" width="200px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.county }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发布商户账户" width="200px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.shopNO }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务状态" width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.shopType=='ONE_PERSON'?'个人':'企业' }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="150px"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{ row }">
          <el-button
            size="small"
            align="center"
            type="primary"
            @click="handleUpdate(row)"
          >
            审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
  </div>
</template>

<script>
// 异步请求 delLly
import { getListPage,examine } from '@/api/verifybusinessListShop/index'
import {
  getAllCat,
} from "@/api/purchase/proCatReq";
import Vue from 'vue'
import {addImg} from '@/api/headWheel'
import { parseTime } from '@/utils'
import eChild from './child'
import Pagination from '@/components/Pagination' // 分页插件

const calendarTypeOptions = [
  { key: 'in', display_name: '内部跳转' },
  { key: 'out', display_name: '外部链接' },
]
const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

export default {
  inject:["reload"],
  components: { Pagination,eChild },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    },
    typeFilter(type) {
      return calendarTypeKeyValue[type]
    },
  },
  data() {
    return {
      changeShow:false,
      tableKey: 0,
      list: null,
      total: 0,
      value1: [],
      listLoading: true,
      listQuery: {
        pageNum: 1,
        pageSize: 10,
      },
      temp: {
      },
      dialogFormVisible: false,
      calendarTypeOptions,
      dialogStatus: '',
      proId:'',
      areaData:[],
      catId:""
    }
  },
  created() {
    this.getList()
    this.getCat()
  },
  methods: {
    getCat(){
      var params={}
      getAllCat(params).then(response => {
        this.areaData=response.data
      });
    },
    getStatus(data){
      this.changeShow=data
      this.getList()
    },
    areaChange(value){
      this.catId=value[1]
      console.log(value)
      console.log(this.$refs['area'].getCheckedNodes())
    },
    goBack() {
        this.changeShow = false;
        this.getList()
    },
    getList() {
      this.listLoading = true
      if(this.value1!==null){
        if(this.value1.length>=2){
        this.beginDate=this.value1[0]
        this.endDate=this.value1[1]
        }else{
          this.beginDate=''
          this.endDate=''
        }
      }else{
        this.beginDate=''
        this.endDate=''
      }
      var params = {
        // pageConvert: true,
        pageNum: this.listQuery.pageNum-1,
        pageSize: this.listQuery.pageSize,
        beginDate:this.beginDate,
        endDate:this.endDate,
        catId:this.catId
      }
      getListPage(params).then(response => {
        this.list = response.data.content
        this.total = response.data.totalElements
        // Just to simulate the time of the request
      })
    },
    handleFilter() {
      this.listQuery.pageNum = 1
      this.getList()
    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    resetTemp() {
      this.temp = {
      }
    },
    handleUpdate(row) {
      this.changeShow = true;
      this.proId=row.proId
      this.$refs.mychild.getCleckList(this.proId)
      console.log(this.proId)
    },
    getSortClass: function(key) {
      const sort = this.listQuery.sort
      return sort === `+${key}`
        ? 'ascending'
        : sort === `-${key}`
          ? 'descending'
          : ''
    }
  }
}
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
